<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="image/css.css" type="text/css" />
<title>管理</title>
</head>
<body>
<?php
include 'configs\config.php';
echo '<h2>应用管理简陋版，以后一步一步完善</h2>';

$show    = @trim($_GET['show']);
$id      = @trim($_GET['id']);
$appname = @trim($_POST['appname']);
$appinfo = @trim($_POST['appinfo']);
$appurl  = @trim($_POST['appurl']);
$appicon = @trim($_POST['appicon']);
$softid  = @trim($_POST['softid']);
$mysql = new mysql();
$mysql->open($config);
$query = $mysql->select('*', 'softapp');

$strHtml = <<< STRHTML
<tr>
<td>编号:__ID__</td>
<td><a href=upload/apk/__APPURL__ >__APPNAME__</a></td>
<td>__APPINFO__</td>
<td><img width="20" height="20" src="upload/img/__APPICON__" /></td>
<td>软件编号:__SOFTID__</td>
<td><a href="?id=__ID__&show=mod">修改</td>
<td><a href="?id=__ID__&show=del" onclick="return confirm('确定要删除吗')">删除</td>
</tr>\r\n
STRHTML;

$strAddHtml = <<< STRHTML
<form action="?show=adddata" method="post">
发布APP的ＩＤ: <input type="text" name="softid"   size="80"><br/>
(此ＩＤ很重要，与我们发布的ＡＰＰ包对应，发布ＡＰＰ之前，必须定出来，以后最好不好,第一款APP，就定为1，此后，以此类推)<br/><br/>
APP名称：<input type="text" name="appname"   size="80"><br/><br/>
APP简介: <textarea name="appinfo" cols="70"></textarea><br/><br/>
APP图标: <input type="text" name="appicon"  size="80"><br/>
(将文件上传至网站根目录upload/img/下面,上面填写文件的名字，名字规则自己定，以后改成网页上传)<br/><br/>
APP包地址:<input type="text" name="appurl"  size="80"><br/>
(将文件上传至网站根目录upload/apk/下面,上面填写文件的名字，名字规则自己定，以后改成网页上传)<br/><br/><br/>
<input type="submit" name="sub" value="提交,提交成后，不给提示，理论上会成功" /><br/>
</form>
STRHTML;
echo $strAddHtml;

$resultHtml = '';
foreach($query as $key=>$value){
	$str = $strHtml;
	$str = str_replace("__ID__", $value['id'], $str);
	$str = str_replace("__SOFTID__", $value['softid'], $str);	
	$str = str_replace("__APPNAME__", $value['appname'], $str);
	$str = str_replace("__APPINFO__", $value['appinfo'], $str);
	$str = str_replace("__APPURL__", $value['appurl'], $str);
	$str = str_replace("__APPICON__", $value['appicon'], $str);	

	$resultHtml = $resultHtml.$str;
}
echo '<table border=0>';
echo $resultHtml;
echo '</table>';


$strModHtml = <<< STRHTML
<br/>
<form action="?id=__ID__&show=moddata" method="post">
发布APP的ＩＤ: <input type="text" name="softid" value="__SOFTID__"  size="80"><br/>
(此ＩＤ很重要，与我们发布的ＡＰＰ包对应，发布ＡＰＰ之前，必须定出来，以后最好不好,第一款APP，就定为1，此后，以此类推)<br/><br/>
APP名称：<input type="text" name="appname" value="__APPNAME__"  size="80"><br/><br/>
APP简介: <textarea name="appinfo" cols="70">__APPINFO__</textarea><br/><br/>
APP图标: <input type="text" name="appicon" value="__APPICON__" size="80"><br/>
(将文件上传至网站根目录upload/img/下面,上面填写文件的名字，名字规则自己定，以后改成网页上传)<br/><br/>
APP包地址:<input type="text" name="appurl" value="__APPURL__" size="80"><br/>
(将文件上传至网站根目录upload/apk/下面,上面填写文件的名字，名字规则自己定，以后改成网页上传)<br/><br/><br/>
<input type="submit" name="sub" value="提交,提交成后，不给提示，理论上会成功" /><br/>
</form>
STRHTML;

$resultHtml = '';
if($show == 'mod'  && !empty($id))
{		
	$where = 'id='.$id;
	$query = $mysql->select('*', 'softapp',$where);

	$appname = $query[0]['appname'];
	$appinfo = $query[0]['appinfo'];
	$appurl  = $query[0]['appurl'];
	$appicon = $query[0]['appicon'];
	$softid  = $query[0]['softid'];
	$str = $strModHtml;
	$str = str_replace("__ID__", $id, $str);
	$str = str_replace("__SOFTID__", $softid, $str);
	$str = str_replace("__APPNAME__", $appname, $str);
	$str = str_replace("__APPINFO__", $appinfo, $str);
	$str = str_replace("__APPURL__",  $appurl, $str);
	$str = str_replace("__APPICON__", $appicon, $str);	
	$resultHtml = $resultHtml.$str;
	echo $resultHtml;
}

if($show == 'moddata' && !empty($id))
{
	$where = 'id='.$id;
	$arr   = array();
	$arr['appname'] = $appname;
	$arr['appinfo'] = $appinfo;
	$arr['appurl']  = $appurl;
	$arr['appicon'] = $appicon;	
	$arr['softid'] = $softid;	
	$res = $mysql->update($arr,'softapp',$where);
	header("location:manage.php");
}
if($show == 'del' && !empty($id))
{
	$where = 'id='.$id;
	$mysql->delete('softapp',$where);
	header("location:manage.php");
}
if($show == 'adddata'){
		$data =array();
		$data['appname'] = $appname;
		$data['appinfo'] = $appinfo;
		$data['appurl']  = $appurl;
		$data['appicon'] = $appicon;	
		$data['softid']  = $softid;
		foreach ($data as $value){
			if($value==''){
				header("location:manage.php");
				exit();
			}
		}
		$res = $mysql->insert($data, 'softapp');
		header("location:manage.php");
}
unset($mysql);
?>
</body>
</html>